<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8" />
        <title>11_innerText和textContent兼容性封装-优化版本</title>
    </head>
    <body>
        <div>优化版本</div>

        <script>
            function getOrSetContent(node,content){
                if(arguments.length == 1) {
                    // if(node.textContent){
                    //     console.log(node.textContent);
                    // }else {
                    //     console.log(node.innerText);
                    // }

                    console.log(node.textContent || node.innerText);

                }else if(arguments.length == 2){
                    // if(node.textContent){
                    //     node.textContent = content;
                    // }else{
                    //     node.innerText = content;
                    // }
                    node.textContent ? node.textContent = content : node.innerText = content;
                }


            }

            var div = document.querySelector('div');

            getOrSetContent(div,'哈哈哈');


        </script>
    </body>
</html>